package com.changgou.search.controller;

import com.changgou.goods.pojo.Sku;
import com.changgou.search.service.SkuService;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/search")
@CrossOrigin
public class SkuController {

    @Autowired
    private SkuService skuService;

    /**
     * 导入数据
     * @return
     */
    @GetMapping(value = "/import")
    public Result importData(){
        skuService.importData();
return new Result(true, StatusCode.OK,"导入数据执行成功！");
    }

    /**
     *关键字搜索
     */
    @GetMapping
    public Map<String,Object> search(@RequestParam(required = false)Map<String,String> searchMapp){
        return skuService.search(searchMapp);
    }

    /**
     * 删除Sku集合
     * @param list
     * @return
     */
    @DeleteMapping
    public Result deleteList(@RequestBody List<Sku> list) {
        skuService.deleteList(list);
        return new Result<>(true,StatusCode.OK,"删除成功");
    }

    /**
     * 修改Sku集合
     * @param list
     * @return
     */
    @PostMapping
    public Result updateList(@RequestBody List<Sku> list) {
        skuService.updateList(list);
        return new Result<>(true,StatusCode.OK,"修改成功");
    }
}
